<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style type="text/css">

        /* tooltip */
        #tooltip{
            position:absolute;
            border:1px solid #ccc;
            background:#333;
            padding:2px;
            display:none;
            color:#fff;
        }
    </style>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">题目管理</li>
            <li><a href="{:url('admin/ques/addSave',['qb_id'=>$qb_id])}" class="a_menu">新增题目</a></li>
        </ul>
    </div>
    <form class="layui-form serch" action="{:url('admin/ques/index')}" method="post">
        <div class="layui-form-item" style="float: left;">
            <div class="layui-input-inline">
                <input type="text" name="question" lay-verify="title" autocomplete="off" placeholder="请输入题目" class="layui-input layui-btn-sm">
            </div>
            <input type="hidden" name="id" value="{$qb_id}">
            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-submit="" lay-filter="serch">搜索</button>
            <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="javascript:history.back(-1);" type="button">返回上一页</button>
        </div>
    </form>
    <table class="layui-table" lay-size="sm">
        <colgroup>
            <col width="50">
            <col width="200">
            <col width="100">
            <col width="100">
            <col width="100">
            <col width="100">
            <col width="100">
            <col width="100">
        </colgroup>
        <thead>
        <tr>
            <th>ID</th>
            <th>题目</th>
            <th>选项A</th>
            <th>选项B</th>
            <th>选项C</th>
            <th>选项D</th>
            <th>答案</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="quess" id="vo"}
        <tr>
            <td>{$vo.id}</td>
            <td>{$vo.question}</td>
            <td>{$vo.A}</td>
            <td>{$vo.B}</td>
            <td>{$vo.C}</td>
            <td>{$vo.D}</td>
            <td>{$vo.answer}</td>
            <td class="operation-menu">
                <div class="layui-btn-group">
                    <a href="{:url('admin/ques/addSave',['id'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu layui-btn-primary" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i>编辑</a>
                    <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger delete" id="{$vo.id}" style="margin-right: 0;font-size:12px;"><i class="layui-icon"></i>删除</a>
                </div>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div style="padding:0 20px;">{$quess->render()}</div>
    {include file="public/foot"}
    <script type="text/javascript">

        $('.delete').click(function(){
            var id = $(this).attr('id');
            layer.confirm('确定要删除?', function(index) {
                $.ajax({
                    url:"{:url('admin/ques/delete')}",
                    data:{id:id},
                    type: 'POST',
                    success:function(res) {
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.href = res.url;
                            },1500)
                        }
                    }
                })
            })
        })
    </script>
    <script type="text/javascript">
        layui.use(['layer'], function() {
            var layer = layui.layer,
                $ = layui.jquery;
            $('.status').click(function () {
                var val = $(this).attr('data-val');
                var id = $(this).attr('data-id');
                var i = $(this).find('i');
                var the = $(this);
                if (val == 1) {
                    var status = 2;
                } else {
                    var status = 1;
                }
                $.ajax({
                    type: "post",
                    url: "{:url('admin/ques/status')}",
                    data: {status: status, id: id},
                    success: function (res) {
                        if (res.code == 1) {
                            tostatus();
                            layer.msg(res.msg);
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                })

                function tostatus() {
                    if (val == 1) {
                        i.attr("class", "fa fa-toggle-off");
                        the.attr('data-val', 2);
                    } else {
                        i.attr("class", "fa fa-toggle-on");
                        the.attr('data-val', 1);
                    }
                }
            })
        });
    </script>
</div>
</body>
</html>
